class stu(object):
    list_info = []
    id = ''
    name = ''
    tel = ''

    def add_stu(self):
        try:
            if len(self.list_info) > 0:
                # flag 用于退出 while 循环
                flag = 0
                while True:
                    self.id = eval(input('请输入您要添加的学生编号：'))
                    for i in range(len(self.list_info)):
                        if self.id in self.list_info[i]:
                            print('error: 此 id 已经存在!\n')
                            break
                        else:
                            flag = 1
                    if flag == 1:
                        break
            else:
                self.id = eval(input('请输入您要添加的学生编号：'))

            self.name = input('请输入您要添加的学生姓名：')
            self.tel = input('请输入您要添加的学生手机号：')
        
            # 临时存储新增学生信息
            list_tmp = []
            list_tmp.append(self.id)
            list_tmp.append(self.name)
            list_tmp.append(self.tel)
            
            self.list_info.append(list_tmp)
        except Exception as e:
            print(f'{e}\n')

    def del_stu(self):
        del_id = eval(input('请输入您要删除的学生编号：'))
        for i in range(len(self.list_info)):
            if del_id in self.list_info[i]:
                del self.list_info[i]
                break

    def modify_stu(self):
        modify_id = eval(input('请输入您要修改的学生编号：'))
        modify_name = input('是否需要修改姓名？是，则输入：true,姓名 否则输入：false。例如：true,张三：').split(',')
        modify_tel = input('是否需要修改手机号？是，则输入：true,手机号 否则输入：false。例如：true,173：').split(',')
        
        for i in range(len(self.list_info)):
            if modify_id in self.list_info[i]:
                if modify_name[0] == 'true':
                    self.list_info[i][1] = modify_name[1]
                if modify_tel[0] == 'true':
                    self.list_info[i][2] = modify_tel[1]
                break

    def show_single_stu(self):
        flag = 0
        select_name = input('请输入您要查询的学生姓名：')
        for i in range(len(self.list_info)):
            if select_name in self.list_info[i]:
                flag = 1
                print(self.list_info[i])
                break

        if flag == 0:
            print("(没有您要查找的数据！)")

    def show_all_stu(self):
        id = "学生编号"
        name = "姓名"
        tel = "手机号"
        print(f"{id:<6}{name:<6}{tel:<6}")
        for list_c in self.list_info:
            print(f'{list_c[0]:<6}\t  {list_c[1]:<6}  {list_c[2]:<6}')

if __name__ == '__main__':
    index_info = '\n1. 添加学生\n2. 删除学生\n3. 修改学生信息\n4. 查询单个学生信息\n5. 查询所有学生信息\n6. 提出系统'
    student = stu()
    while True:
        print(index_info)
        num = input('请输入您要操作的编号：')
        if num == '1':
            student.add_stu()
        elif num == '2':
            student.del_stu()
        elif num == '3':
            student.modify_stu()
        elif num == '4':
            student.show_single_stu()
        elif num == '5':
            student.show_all_stu()
        elif num == '6':
            print('\n系统已退出！')
            break
        else:
            print('请输入0~6内的数字！')